package distrcomp;

public class ShippingSimulator extends Thread {
	private Shipment shipment;
	
	//Constructor
	public ShippingSimulator(Shipment shipment) {
		this.shipment = shipment;
	}
	
	//Run-method
	//Simulates the process of shipping a product by changing state after 10s
	public void run() {
		while(this.shipment.getShippingState() != ShippingState.ARRIVED) {
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			switch(this.shipment.getShippingState()) {
				case PENDING:
					this.shipment.setShippingState(ShippingState.IN_ROUTE);
					System.out.println("Update: shipment " + shipment.getID() + " from pending to in route.");
					break;
				case IN_ROUTE:
					this.shipment.setShippingState(ShippingState.ARRIVED);
					System.out.println("Update: shipment " + shipment.getID() + " from in route to arrived.");
					break;
				default:
					break;
			}
		}
	}
}